<?php
class CdeUnit extends AppModel {
	var $name = 'CdeUnit';
	//The Associations below have been created with all possible keys, those that are not needed can be removed
	var $hasMany = array(
		'CdeModule' => array(
			'className' => 'CdeModule',
			'foreignKey' => 'cde_unit_id',
			'dependent' => false,
			'conditions' => '',
			'fields' => '',
			'order' => '',
			'limit' => '',
			'offset' => '',
			'exclusive' => '',
			'finderQuery' => '',
			'counterQuery' => ''
		)
	);
	function getUnitStatus($unitid=null,$userid=null) {
		$status="New";
		$userunit=$this->query('SELECT * FROM cde_users_units where cde_unit_id='.$unitid.' and uid = '.$userid);
		$moduleinunit=array();
		$usermodule=$this->query('SELECT * FROM cde_users_modules where uid= '.$userid.' and cde_module_id in (select id FROM cde_modules where cde_unit_id='.$unitid.')');
		if (count($userunit)>0) {//unit has been completed
			$status="Completed";
		}else if (count($usermodule)>0) {//unit has not been completed and some modules have been completed
			$status="Uncompleted";
		}
		return $status;
	}
}
?>